import java.util.*;


public class Solution9 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param str string字符串 
     * @return string字符串ArrayList
     */
    public ArrayList<String> Permutation (String str) {
        // write code here
    
        ArrayList<String> res = new ArrayList<>();
        char[] ch = str.toCharArray();
        boolean[] dp = new boolean[ch.length];
        Arrays.sort(ch);
        fun(res,new StringBuilder(),dp,ch);
        return res;
    }
    public void fun(ArrayList<String> res,StringBuilder s,boolean[] dp,char[] ch) {
        if(s.length() == ch.length) {
            if(!res.contains(new String(s)))
            res.add(new String(s));
            return;
        } 
        for(int i = 0;i<ch.length;i++) {
            if(dp[i]) {
                continue;
            }else if(i>0&&ch[i]==ch[i-1]&&!dp[i-1]) {
                continue;
            } else if(!dp[i]) {
                dp[i] = true;
                s.append(ch[i]);
                fun(res,s,dp,ch);
                dp[i] = false;
                s.deleteCharAt(s.length()-1);
            }
        }
    }
}